package gphoto.util;

import gphoto.services.impl.OptionServicesImpl;

import java.sql.SQLException;
import java.util.StringTokenizer;

public class GPhotoUtil {

	public static String getURL(String url) {

		url = url.replaceFirst(":", "");
		
		// la 1er lettre en minuscule
		url = url.substring(0, 1).toLowerCase()+url.substring(1);
		
		StringTokenizer st = new StringTokenizer(url, "\\");
		
		StringBuffer sb;
		try {
			if (OptionServicesImpl.getInstance().getNomServeur() != null) {
				sb = new StringBuffer("http://"+OptionServicesImpl.getInstance().getNomServeur()+":8080/gPhoto/img");
			} else {
				sb = new StringBuffer("http://localhost:8080/gPhoto/img");
			}
		} catch (SQLException e) {
			sb = new StringBuffer("http://localhost:8080/gPhoto/img");
		}
		
		while (st.hasMoreTokens()) {
			sb.append("/").append(st.nextToken());
		}
		
		url = sb.toString();
		
		return url;
	}
}
